package operation;

import book.Book;
import book.BookLise;

import java.util.Scanner;

/*
     FindOperation类：用于实现图书的查找
                     通过输入查找书籍来遍历书架寻找
                     该书书架有，打印出该书的信息
                     该书书架不存在，则未找到

*/

public class FindOperation implements IOperation {

    //重写接口标准方法 work
    @Override
    public void work(BookLise bookLise) {
        System.out.println("查找图书");

        //输入查找书的名字
        System.out.println("请输入你需要查找的图书名字");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        //遍历书架寻找
        for (int i = 0; i < bookLise.getNowSize(); i++) {
            if(name.equals(bookLise.getBooks(i).getName())){

                //找到了打印出书的信息并且退出
                System.out.println("找到了"+ "《"+ name + "》");
                System.out.println(bookLise.getBooks(i));
                return;
            }
        }

        //遍历书架未找到该书
        System.out.println("未找到"+ "《"+ name + "》");
    }
}
